#!/usr/bin/env bash
# install_keyboard_shortcut=F4

# Source the script 'common-functions.sh'.
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
source "$ROOT_DIR/common-functions.sh"

_main() {
    local input_files=""

    # Execute initial checks.
    _check_dependencies ""
    input_files=$(_get_files "par_type=directory; par_max_items=20; par_get_pwd=true")
    _unset_global_variables_file_manager

    _open_app "$input_files"
}

_open_app() {
    local input_files=$1
    local input_file=""

    for input_file in $input_files; do
        # Run the main process.
        cd "$input_file" || exit 1
        if _command_exists "alacritty"; then
            alacritty &
        elif _command_exists "kitty"; then
            kitty &
        elif _command_exists "terminology"; then
            terminology &
        elif _command_exists "terminator"; then
            terminator &
        elif _command_exists "kgx"; then
            kgx &
        elif _command_exists "gnome-terminal"; then
            gnome-terminal &
        elif _command_exists "konsole"; then
            konsole &
        elif _command_exists "mate-terminal"; then
            mate-terminal &
        elif _command_exists "xfce4-terminal"; then
            xfce4-terminal &
        elif _command_exists "qterminal"; then
            qterminal &
        elif _command_exists "deepin-terminal"; then
            deepin-terminal &
        elif _command_exists "termit"; then
            termit &
        elif _command_exists "uxterm"; then
            uxterm &
        elif _command_exists "xterm"; then
            xterm &
        fi
    done
}

_main "$@"
